package com.shoppingmalltest.shoppingmalltest.order.controller;

import java.util.Arrays;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.shoppingmalltest.shoppingmalltest.order.feign.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.shoppingmalltest.shoppingmalltest.order.entity.OrderEntity;
import com.shoppingmalltest.shoppingmalltest.order.service.OrderService;
import com.shoppingmalltest.common.utils.PageUtils;

import com.shoppingmalltest.common.utils.R;



/**
 * 订单
 *
 * @author libo
 * @email 1666737385@qq.com
 * @date 2020-07-25 23:14:07
 */
@RefreshScope
@RestController
@RequestMapping("order/order")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /*
    * 测试远程调用
    * */
    @Autowired
    private OrderFeignService orderFeignService;

    /*
    * 测试nacos配置中心
    * */
    @Value("${order.user.username}")
    private String username;
    @Value("${order.user.age}")
    private String age;
    @RequestMapping("/listTest")
    //@RequiresPermissions("order:order:list")
    public R listTest() {
        orderFeignService.Test();
        return R.ok();
    }
    /*
    * 测试nacos配置中心
    * */
        @RequestMapping("/listTestNacos")
    //@RequiresPermissions("order:order:list")
    public R listTestNacos() {
        return R.ok().put("姓名：",username).put("年龄：",age);
    }
        /**
         * 列表
         */
    @RequestMapping("/list")
    //@RequiresPermissions("order:order:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
   // @RequiresPermissions("order:order:info")
    public R info(@PathVariable("id") String id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
   // @RequiresPermissions("order:order:save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("order:order:update")
    public R update(@RequestBody OrderEntity order){
		orderService.updateById(order);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("order:order:delete")
    public R delete(@RequestBody String[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
